<?php
namespace V1;
class E_CustomerList extends \ResourceClass {
    public $isActive = true;
    public $remark = '获取客户列表';
    public function get(array $req, array $post, &$result)
    {   
        if (!isset($req['uid'])) {
            return 'require user id ';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        if (!isset($req['enterpriseId'])) {
            return 'require enterpriseId';
        }
        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $req['enterpriseId'], $req['t'], $req['k']) !== true) {
            return 'data illegal';
        }
        // 获取客户列表
        $result = array();
        $limit = isset($req['l']) ? $req['l'] : 20;
        $offset = isset($req['o']) ? $req['o'] : 0;
        $enterprise_id = $req['enterpriseId'];
        $tabulation = new \Cls\Tabulation();
        $tabulation->setOffset($offset)->setLimit($limit)->setOrderBy('insert_time', 'desc');
        \Biz\EnterpriseCustomerHandler::getEnterpriseCustomerListByEnterpriseId($enterprise_id, $tabulation);
        if ($tabulation->getSuccessStatus() !== true) {
            return '未获取到用户列表';
        }
        $customer_cls_arr = $tabulation->getData();
        $result['lists'] = array();
        foreach ($customer_cls_arr as $key => $customer_cls) {
            $list['id'] = $customer_cls->getId();
            $list['account'] = $customer_cls->getAccount();
            $list['company'] = $customer_cls->getCompany();
            $list['contact'] = $customer_cls->getContact();
            $list['enterprise_id'] = $customer_cls->getEnterpriseId();
            $list['pwd'] = $customer_cls->getPassword();
            $list['tel'] = $customer_cls->getTelephone();
            // is_use 和 is_del 两者表示的是相反的,不要纠结,就是反的
            $list['is_del'] = $customer_cls->getUseStatus() === \Cls\User\EnterpriseCustomer::USE_STATUS_ON ? \Cls\User\EnterpriseCustomer::USE_STATUS_OFF : \Cls\User\EnterpriseCustomer::USE_STATUS_ON;
            $list['channelname'] = $customer_cls->getChannelInfo()->getName();
            $result['lists'][] = $list;
        }
        $result['total'] = $tabulation->getTotal();
        return '';
    }
}